package adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sxpjyy.monkey.mobilenurse.R;

import java.util.List;

import objects.LisJYXM;

/**
 * Created by Monkey on 2017/3/10.
 * 检验项目适配器
 */

public class JYXMListAdapter extends BaseAdapter {

    private Context mContext;
    private List<LisJYXM> list;
    private LayoutInflater inflater;

    public JYXMListAdapter(Context context) {
        mContext = context;
        this.inflater = LayoutInflater.from(context);
    }

    public void setList(List<LisJYXM> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        if (list != null && list.size() > 0) {
            return list.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        if (list != null && list.get(position) != null) {
            return list.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_jyxm, parent, false);
            holder.jy_name = (TextView) convertView.findViewById(R.id.jy_name);
            holder.sq_date = (TextView) convertView.findViewById(R.id.jy_date_sq);
            holder.jy_date = (TextView) convertView.findViewById(R.id.jy_date_jy);
            holder.jy_doctor = (TextView) convertView.findViewById(R.id.jy_doctor);
            holder.jy_status = (TextView) convertView.findViewById(R.id.jy_status);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (list != null && list.size() > 0) {
            if (list.get(position) != null) {
                LisJYXM jyxm = list.get(position);
                if (jyxm.getJYXM() != null) {
                    holder.jy_name.setText(jyxm.getJYXM());
                }
                if (jyxm.getSQRQ() != null) {
                    holder.sq_date.setText(jyxm.getSQRQ().substring(0, 10));

                }
                if (jyxm.getJYRQ() != null) {
                    holder.jy_date.setText(jyxm.getJYRQ().substring(0, 10));
                }
                if (jyxm.getSQYS() != null) {
                    holder.jy_doctor.setText(jyxm.getSQYS());
                }
                if (jyxm.getBGDH() != null && !jyxm.getBGDH().equals("")) {
                    holder.jy_status.setText("已报告");
                    holder.jy_status.setTextColor(mContext.getResources().getColor(R.color.colorBlue));
                } else {
                    holder.jy_status.setText("未报告");
                    holder.jy_status.setTextColor(mContext.getResources().getColor(R.color.colorRed));
                }
            }
        }
        return convertView;
    }

    private class ViewHolder {
        private TextView jy_name;
        private TextView sq_date;
        private TextView jy_date;
        private TextView jy_doctor;
        private TextView jy_status;
    }
}
